﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Morro.VPN.Desktop.DataDisplay
{
    public class Ritmogramm : BaseGraph
    {
        private List<int> _points;
        private List<int> _time;


        public void ShowData(List<int> points, List<int> time)
        {
            _points = points;
            _time = time;
            UpdateUICore();
        }

        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            if (_points == null || _points.Count == 0)
                return;

            double time = (_time[_time.Count - 1] - _time[0]);

            double timePerPixel = DrawAreaWidth/time;
            double maxX = _points.Max();
            double min = _points.Min();

            double step = DrawAreaWidth/_points.Count;


            bool preveous = false;
            Point pre  = new Point( 0 ,0);


            double middleSum = 0;            
            double x = 0;
            for (int i = 0; i < _points.Count; i++)
            {
                double k = (_points[i] - min) / (maxX - min);
                Point p1 = TranslateToCanvas(x, k * (DrawAreaHeight - 0.2 * DrawAreaHeight) + 0.1 * DrawAreaHeight);
                dc.DrawEllipse(Brushes.Red,null,p1,1,1);
                x += step;

                if(preveous)
                {
                    dc.DrawLine(new Pen(Brushes.Green,1),pre,p1);
                }

                preveous = true;
                pre = p1;

                middleSum += _points[i];
            }

            //middleSum = middleSum/_points.Count;

            SetCaption("Ритмограмма (" + _points.Count +")");




            //int x = 10;
            //for (int i = 0; i < _points.Count; i++)
            //{

            //    Point p1 = TranslateToCanvas(x, 0);
            //    Point p2 = TranslateToCanvas(x + 20, gist[i] * 10);
            //    Brush rectBrush = new SolidColorBrush(Colors.YellowGreen);
            //    Pen border = new Pen(rectBrush, 1);

            //    dc.DrawRectangle(null, border, new Rect(p1, p2));


            //    x += 30;
            //}


        }
    }
}
